using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;
using System.Threading;
using System.Windows.Forms;


namespace ConnectionTypes
{
    interface Connections
    {
        void createConnection();
        void connect(System.Net.IPAddress hostAddress, int port);
        void send(ref byte[] buffer, int length);
        void receive(ref byte[] buffer, int length);
    }



    class tcpServer : Connections
    {
        int tcpPort;
        Socket connection;
        TcpListener serverListener;

        public tcpServer(int Port)
        {
            tcpPort = Port;
            serverListener = new TcpListener(System.Net.IPAddress.Parse("172.25.25.193"), tcpPort);
        }

        public void createConnection()
        {

            serverListener.Start();
            connection = serverListener.AcceptSocket();
            MessageBox.Show("Client connected el 7amd l Allah :)");
        }

        public void connect(System.Net.IPAddress hostAddress, int port)
        {

        }

        public void send(ref byte[] buffer, int length)
        {
            connection.Send(buffer, length, SocketFlags.None);
        }

        public void receive(ref byte[] buffer, int length)
        {
            connection.Receive(buffer, length, SocketFlags.None);
        }
    }

    class tcpClient : Connections
    {

        TcpClient client;

        public tcpClient()
        {
            client = new TcpClient();
        }

        public void createConnection()
        {

        }

        public void connect(System.Net.IPAddress hostAddress, int port)
        {
            client.Connect(hostAddress, port);
        }

        public void send(ref byte[] buffer, int length)
        {
            client.Client.Send(buffer, length, SocketFlags.None);
        }

        public void receive(ref byte[] buffer, int length)
        {
            client.Client.Receive(buffer, length, SocketFlags.None);
        }
        
       
    }



}


